<template>
  <div class="card form-card">
    <h2>{{ $t('login.title') }}</h2>
    <form @submit.prevent="onSubmit">
      <div class="form-row">
        <label>{{ $t('login.idNumber') }}</label>
        <input v-model="form.idNumber" required />
      </div>
      <div class="form-row">
        <label>{{ $t('login.password') }}</label>
        <input type="password" v-model="form.password" required />
      </div>
      <a class="link" href="#" @click.prevent="onForgot">{{ $t('login.forgot') }}</a>
      <div style="margin-top: 12px;">
        <button class="btn-primary" type="submit">{{ $t('login.submit') }}</button>
      </div>
    </form>
    <div style="margin-top: 12px;">
      <router-link class="link" to="/register">{{ $t('login.noAccount') }}</router-link>
    </div>
  </div>
</template>

<script>
import axios from 'axios'

export default {
  name: 'LoginView',
  data() {
    return {
      form: {
        idNumber: '',
        password: ''
      }
    }
  },
  methods: {
    async onSubmit() {
      try {
        const { data } = await axios.post('/api/auth/login', this.form)
        localStorage.setItem('token', data.token)
        this.$router.push('/profile')
      } catch (e) {
        console.error(e)
        alert('Login failed')
      }
    },
    onForgot() {
      this.$router.push('/reset-password')
    }
  }
}
</script>

<style scoped>
</style> 